package com.example.hcd.tool;

import org.apache.http.client.HttpClient;

import com.example.hcd.R;

import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;

public class MyLoadingDialog {
	public boolean mCancel = false;
	private HttpClient mHttpClient;
	private Context context;
	private CProgressDialog mDialog;
	private XListView list = null;
	public MyLoadingDialog(Context context,HttpClient mHttpClient,String content,boolean iscancel) {
		this.context = context;
		this.mHttpClient = mHttpClient;
		this.mCancel = iscancel;
		
//		mDialog = ProgressDialog.show(context,null,content,false,true);
		mDialog = new CProgressDialog(context,R.style.CustomDialog);
		mDialog.setMessage(content);
		mDialog.show();
		init();
	}
	public void init()
	{
		
		mDialog.setCanceledOnTouchOutside(false);
		mDialog.setOnCancelListener(new OnCancelListener()
		{

			@Override
			public void onCancel(DialogInterface arg0) {
				// TODO Auto-generated method stub
				cancel();
		}}); 
	}
	
	public void cancel()
	{
		if (mCancel) {
            return;
        }
		dimiss();
        mCancel = true;
        if (mHttpClient != null) {
            mHttpClient.getConnectionManager().shutdown();
        }
        
        //LinkHelp.shutdownHttpClient();
        if(list!=null)
        {
        	list.stopRefresh();
        	list.stopLoadMore();
        }
		
	}
	
	public void setPullToRefreshListView(XListView list)
	{
		this.list = list;
	}
	
	
	public void dimiss()
	{
		mDialog.dismiss();
	}
	
	public void show()
	{
		mDialog.show();
	}

}
